package myUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class DrawUtils {

	public static void main(String[] args) {
		double[] probability = { 25.00, 50.00, 75.00, 100.00 };
		List<Integer> list = new ArrayList<Integer>();
		list.add(0);
		list.add(0);
		list.add(0);
		list.add(0);
		for (int i = 0; i < 1000000; i++) {
			int temp = draw(probability);
			list.set(temp, list.get(temp) + 1);
		}
		System.out.println(list);

	}

	public static int draw(double[] probability) {
		int l = probability.length;
		Random random = new Random();
		double d = random.nextDouble() * 100;

		int left = 0;
		int right = l - 1;
		int res = 0;
		while (left <= right) {
			int mid = left + (right - left) / 2;
			if (probability[mid] > d) {
				res = mid;
				right = mid - 1;
			} else
				left = mid + 1;
		}
		return res;
	}

}
